package com.open.capacity.user.controller;

import com.open.capacity.common.model.Group;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.user.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/group")
public class GroupController {
    @Autowired
    private GroupService groupService;

    @PostMapping("/getGroupByTeacher")
    public PageResult getGroupByTeacher(@RequestParam Map<String,Object> params){
        return groupService.selectGroupByTeacher(params);
    }

    @PostMapping("/addGroup")
    public Result addGroup(@RequestBody Group group){
        return groupService.addGroup(group);
    }

    @GetMapping("/deleteGroupById")
    public Result deleteGroupById(@RequestParam int id){
        return groupService.deleteGroupById(id);
    }

    @GetMapping("/updateGroupType")
    public Result updateGroupType(@RequestParam Map<String,Object> params){
        return groupService.updateGroupType(params);
    }

    @GetMapping("/getCheckGroupMember")
    public Result getCheckGroupMember(@RequestParam int id){
        return groupService.getCheckGroupMember(id);
    }

    @GetMapping("/addGroupMember")
    public Result addGroupMember(@RequestParam int grouid,@RequestParam List<Long> ids){
        Map params = new HashMap();
        params.put("grouid", grouid);
        params.put("ids",ids);
        return groupService.addGroupMember(params);
    }

    @GetMapping("/removeGroupMember")
    public Result removeGroupMember(@RequestParam int grouid,@RequestParam List<Long> ids){
        Map params = new HashMap();
        params.put("grouid", grouid);
        params.put("ids",ids);
        return groupService.removeGroupMember(params);
    }
    
    @PostMapping("/updateGroup")
    public Result updateGroup(@RequestBody Group group){
        return groupService.updateGroup(group);
    }

    @GetMapping("/getGroupByMember")
    public Result getGroupByMember(@RequestParam Long userid){
        return groupService.selectGroupByMember(userid);
    }

    @PostMapping("/selectUserByGroup")
    public PageResult selectUserByGroup(@RequestParam Map<String,Object> params){
        return groupService.selectUserByGroup(params);
    }
}
